package com.example.luozizhao.eprxdemo.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.blankj.utilcode.util.ToastUtils;
import com.example.luozizhao.eprxdemo.R;
import com.example.luozizhao.eprxdemo.base.activity.BaseActivity;
import com.example.luozizhao.eprxdemo.presenter.LoginPresenter;
import com.jakewharton.rxbinding2.view.RxView;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;


public class LoginActivity extends BaseActivity<LoginPresenter>{
    private static final int CLICK_LOGIN_INTERVAL = 3000;
    private static final String TAG = "LoginActivity";
    @BindView(R.id.three_iv)
    ImageView threeIv;
    @BindView(R.id.login_iv_phonenum)
    ImageView loginIvPhonenum;
    @BindView(R.id.login_et_phonenum)
    EditText loginEtPhonenum;
    @BindView(R.id.login_iv_password)
    ImageView loginIvPassword;
    @BindView(R.id.login_et_password)
    EditText loginEtPassword;
    @BindView(R.id.login_cb_show_passward)
    CheckBox loginCbShowPassward;
    @BindView(R.id.login_rl_input)
    RelativeLayout loginRlInput;
    @BindView(R.id.btn_login)
    Button btnLogin;

    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    public void initData() {
        mPresenter.requestPermissions();
        mPresenter.addSubscribe(RxView.clicks(btnLogin)
                .throttleFirst(CLICK_LOGIN_INTERVAL, TimeUnit.MILLISECONDS)  // 过滤少于3000mms的事件。
                .subscribe(o -> {
                    mPresenter.login(loginEtPhonenum.getText().toString(), loginEtPassword.getText().toString());
                }));
        ToastUtils.showShort(""+mPresenter.a);
    }



   /* @OnClick({R.id.btn_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_login:
                String userName = loginEtPhonenum.getText().toString().trim();
                String password = loginEtPassword.getText().toString().trim();
                mPresenter.login(userName,password);
             *//*   Observable<GetNounceRespBean> tattedCode = RetrofitHelper.getInstance().getTattedCode();
                tattedCode.compose(RxUtils.rxSchedulerHelper()).subscribe(new Consumer<GetNounceRespBean>() {
                    @Override
                    public void accept(GetNounceRespBean getNounceRespBean) throws Exception {
                        LogUtils.d(TAG,"成功");
                        LogUtils.d(TAG,"tattedCode:"+getNounceRespBean.data);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        LogUtils.d(TAG,"失败 "+throwable.getMessage());
                    }
                });*//*
                break;
        }
    }*/


    public void loginSuccess() {
        ToastUtils.showShort("登录成功");
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

}
